package Meituan;

import java.util.Scanner;

/**
 * @author: leiwenkang02@meituan.com
 * @date: 2018/5/31
 * @time: 19:32
 */
public class Test15 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int originPrice = 0;
        //若不做满减，做特价
        double discountPrice = 0.0;
        for (int i = 1; i <= n; i++) {
            int price = sc.nextInt();
            originPrice += price;
            int hasDicountPrice = sc.nextInt();
            if (hasDicountPrice == 1) {
                discountPrice += price * 0.8;
            } else {
                discountPrice += price;
            }
        }
        //若全部做满减，不做特价
        int maxReduce = 0;
        for (int i = n + 1; i <= m + n; i++) {
            int thresh = sc.nextInt();
            int reduce = sc.nextInt();
            if (originPrice >= thresh && reduce > maxReduce) {
                maxReduce = reduce;
            }
        }
        int fullFillPrice = originPrice - maxReduce;


        System.out.println(discountPrice <= fullFillPrice ? discountPrice : fullFillPrice);
    }

    public static double getResult(int[][] array) {
        int n = array[0][0];
        int m = array[0][1];
        int originPrice = 0;
        for (int i = 1; i <= n; i++) {
            originPrice += array[i][0];
        }
        //若全部做满减，不做特价
        int maxReduce = 0;
        for (int i = n + 1; i <= m + n; i++) {
            if (array[i][0] >= originPrice && array[i][1] > maxReduce) {
                maxReduce = array[i][1];
            }
        }
        int fullFillPrice = originPrice - maxReduce;

        //若不做满减，做特价
        double discountPrice = 0.0;
        for (int i = 1; i <= n; i++) {
            if (array[i][1] == 1) {
                discountPrice += array[i][0] * 0.8;
            } else {
                discountPrice += array[i][0];
            }
        }
        return discountPrice <= fullFillPrice ? discountPrice : fullFillPrice;

    }
}
